/*
**    Name: support.c
**
**    Date: Fri Aug  1 21:15:51 2003
**
*/

/* Pulled from other libraries (mine - don't worry I haven't pinched this!) */

#include "support.h"

char *messagetrans_simplelookup(char *token)
    {
    int used;

    char *result;

    if (xmessagetrans_lookup(&MessageTrans_Control_Block,
                         token,
                         NULL,
                         0,
                         NULL,
                         NULL,
                         NULL,
                         NULL,
                         &result,
                         &used) != NULL)
        {
        return token;
        }

    return result;
    }


osbool report_prompt(char *message)
    {
    os_error error;

    wimp_error_box_flags flags;

    wimp_error_box_selection click;

    flags = wimp_ERROR_BOX_OK_ICON | wimp_ERROR_BOX_CANCEL_ICON |
            (wimp_ERROR_BOX_CATEGORY_QUESTION << wimp_ERROR_BOX_CATEGORY_SHIFT);

    error.errnum = (bits)0;

    string_copy(error.errmess,message);

    REPERRCONT(xwimp_report_error(&error,
                               flags,
                               messagetrans_simplelookup("_TaskName"),
                               &click));

    if (click == wimp_ERROR_BOX_SELECTED_OK)
        {
        return TRUE;
        }
    else
        {
        return FALSE;
        }

    return FALSE;
    }


osbool check_report_error(os_error *error)
    {
    if (error != NULL)
        {
        if (error->errnum != 0)
            {
            report_error(error->errnum,
                         error->errmess);
            return TRUE;
            }
        }

    return FALSE;
    }


void report_error(int error_number,
                  char *message)
    {
    os_error error;

    wimp_error_box_flags flags;

    wimp_error_box_selection click;

    flags = wimp_ERROR_BOX_OK_ICON;

    error.errnum = (bits)error_number;

    string_copy(error.errmess,message);

    ERRVOID(xwimp_report_error(&error,
                               flags,
                               messagetrans_simplelookup("_TaskName"),
                               &click));
    }
